package org.jeecg.modules.online.config.service.p023a;

import java.util.List;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.auth.p004b.AuthConstants;
import org.jeecg.modules.online.cgform.consts.ExtendJsonKey;
import org.jeecg.modules.online.cgform.utils.CgformUtil;
import org.jeecg.modules.online.config.p022d.ColumnMeta;
import org.jeecg.modules.online.config.service.DbTableHandleI;

/* renamed from: org.jeecg.modules.online.config.service.a.c */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/config/service/a/c.class */
public class DbTableHyperSQLHandleImpl implements DbTableHandleI {
    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String getAddColumnSql(ColumnMeta columnMeta) {
        String str = " ADD " + columnMeta.getColumnName() + " " + m16a(columnMeta);
        if (oConvertUtils.isNotEmpty(columnMeta.getFieldDefault())) {
            str = str + " DEFAULT " + columnMeta.getFieldDefault();
            if (!"Y".equals(columnMeta.getIsNullable())) {
                str = str + " NOT NULL";
            }
        }
        return str;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String getMatchClassTypeByDataType(String dataType, int digits) {
        String str;
        String lowerCase = dataType.toLowerCase();
        if ("date".equals(lowerCase) || "time".equals(lowerCase)) {
            str = "date";
        } else if ("timestamp".equals(lowerCase)) {
            str = "datetime";
        } else if ("numeric".equals(lowerCase)) {
            str = "bigdecimal";
        } else if ("double".equals(lowerCase)) {
            str = "double";
        } else if ("integer".equals(lowerCase)) {
            str = "int";
        } else if ("clob".equals(lowerCase)) {
            str = ExtendJsonKey.f133f;
        } else if ("blob".equals(lowerCase)) {
            str = "blob";
        } else {
            str = "string";
        }
        return str;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String dropTableSQL(String tableName) {
        return " DROP TABLE  " + tableName.toUpperCase() + " ";
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String getDropColumnSql(String fieldName) {
        return " DROP COLUMN " + fieldName.toUpperCase() + "";
    }

    /* renamed from: a */
    private String m16a(ColumnMeta columnMeta) {
        String format;
        String lowerCase = columnMeta.getColunmType().toLowerCase();
        boolean z = true;
        switch (lowerCase) {
            case "double":
            	format = "double";
                break;
            case "string":
            	format = String.format("varchar(%s)", Integer.valueOf(columnMeta.getColumnSize()));
                break;
            case "int":
            	 format = "INTEGER";
                break;
            case "blob":
            	format = "BLOB";
                break;
            case "date":
            	 format = "DATE";
                break;
            case "text":
            	format = "CLOB";
                break;
            case "datetime":
            	 format = "TIMESTAMP";
                break;
            case "bigdecimal":
            	format = String.format("NUMERIC(%s, %s)", Integer.valueOf(columnMeta.getColumnSize()), Integer.valueOf(columnMeta.getDecimalDigits()));
                break;
            default:
                format = String.format("varchar(%s)", Integer.valueOf(columnMeta.getColumnSize()));
                break;
        }
        return format;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String getReNameFieldName(ColumnMeta columnMeta) {
        return " change " + columnMeta.getOldColumnName() + " " + columnMeta.getColumnName() + " " + m16a(columnMeta);
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String getCommentSql(ColumnMeta columnMeta) {
        return "COMMENT ON COLUMN " + columnMeta.getTableName() + "." + columnMeta.getColumnName() + " IS '" + columnMeta.getComment() + CgformUtil.f231C;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String getUpdateColumnSql(ColumnMeta cgformcolumnMeta, ColumnMeta datacolumnMeta) {
        return null;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String getSpecialHandle(ColumnMeta cgformcolumnMeta, ColumnMeta datacolumnMeta) {
        return null;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String dropIndexs(String indexName, String tableName) {
        return "DROP INDEX " + indexName;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public String countIndex(String indexName, String tableName) {
        return "select count(*) from user_ind_columns where index_name=upper('" + indexName + "')";
    }

    /* renamed from: a */
    private boolean m17a(String str) {
        String[] strArr = {"clob", "blob", ExtendJsonKey.f133f, "date", "double", "int"};
        boolean z = false;
        int i = 0;
        while (true) {
            if (i >= strArr.length) {
                break;
            } else if (!strArr[i].equals(str)) {
                i++;
            } else {
                z = true;
                break;
            }
        }
        return z;
    }

    @Override // org.jeecg.modules.online.config.service.DbTableHandleI
    public void handleUpdateMultiSql(ColumnMeta meta, ColumnMeta config, String tableName, List<String> sqlList) {
        String columnName = config.getColumnName();
        String colunmType = meta.getColunmType();
        String colunmType2 = config.getColunmType();
        boolean z = false;
        if ((!colunmType.equals(colunmType2) || meta.getColumnSize() != config.getColumnSize() || meta.getDecimalDigits() != config.getDecimalDigits()) && (!colunmType.equals(colunmType2) || !m17a(colunmType2))) {
            z = true;
        }
        if ("Y".equals(config.getIsNullable()) && !config.getIsNullable().equals(meta.getIsNullable())) {
            z = true;
        }
        if ("N".equals(config.getIsNullable()) && !config.getIsNullable().equals(meta.getIsNullable())) {
            z = true;
        }
        String fieldDefault = meta.getFieldDefault();
        String fieldDefault2 = config.getFieldDefault();
        if ((!oConvertUtils.isEmpty(fieldDefault) || !oConvertUtils.isEmpty(fieldDefault2)) && !fieldDefault2.equals(fieldDefault)) {
            z = true;
        }
        if (z) {
            String format = String.format("alter table %s", tableName);
            sqlList.add(format + getDropColumnSql(meta.getColumnName()));
            sqlList.add(format + getAddColumnSql(config));
        }
        if (!meta.m59b(config)) {
            sqlList.add(String.format("COMMENT ON COLUMN %s.%s IS '%s'", tableName, columnName, config.getComment()));
        }
    }
}
